home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9856 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: news.pi.net!news
  2. From: Marc Lucassen <lucassen@pi.net>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: how to delete data in file? help
  5. Date: Mon, 04 Mar 1996 21:34:43 -0800
  6. Organization: prive
  7. Message-ID: <313BD273.162B@pi.net>
  8. References: <4helpk$50c@lantana.singnet.com.sg>
  9. NNTP-Posting-Host: ams82.pi.net
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0b3 (Win16; I)
  14.  
  15. Mikhail Choo W.M. wrote:
  16. > HI there,
  17. >    I know this may seem like a real stupid question, but I had to ask. If say
  18. > for example I needed to delete a string of data form a file, how do I go about
  19. > doing it. I can't just write over the data to delete, because the result would
  20. > be a file of the same length with white space chracters. So how does one delete
  21. > the data in such a way that once the data segment is deleted, the rest of the
  22. > data would neatly pack themselves over the deleted area to  ensure a release of
  23. > space. I know one way to solve the problem, but it seems very long-winded. The
  24. > method involves reading all the data in the file to memory, deleteing the
  25. > unwanted area, and the re-write the data back to clean file. I am currently
  26. > using Borland C++ 4.5, and I can't find any function that does the job. OK OK,
  27. > to summerise, the problem is that I can't seem to find a way to directly delete
  28. > a data segment form a file, without reading into memory first. So any ideas, and
  29. > help would be greatly appreciated. Thanks in advance .
  30. > --------------------------------------------------------
  31. > Yours, Mikhail Choo W. M.
  32. >                                    Carpedium!
  33. > E-Mail: mikhail@singnet.com.sg        sieze the day...
  34. >         s7700017@singnet.com.sg
  35. > --------------------------------------------------------
  36.  
  37. There are a two possible ways of deleting data.
  38. 1. The strings all have the same size, you have to make a record with a 
  39. string field of that size and a pointer field to the next record. You can 
  40. insert a new string. You have to order them or read them directly from the 
  41. file. This method can be done when you are making a database and is 
  42. difficult.
  43. 2. Reading a byte (or string) from the old file and writing it to a new file 
  44. without te deleted data. This is easier and better then reading the whole 
  45. file at once.
  46. After this you copy the new file over the old file and delete the temporary 
  47. file.
  48.  
  49. The second method is the normal method for sequentialy readed files, used by 
  50. professional programmer.
  51.